package edu.sctu.practice.class02.yangyuran.test03;

import java.io.IOException;
import java.util.Scanner;

/**
 * Created by Administrator on 2015/10/9.
 */
public class MyTime {
    private int hour;
    private int minute;
    private int second;

    public MyTime() {

        hour = 10;
        minute = 10;
        second = 10;
    }


    public void addSecond() {

        System.out.println("请输入要增加的秒数：");
        try {
            Scanner scan = new Scanner(System.in);
            int second = scan.nextInt();
            this.second = this.second + second;
            if (this.second > 61) {
                throw new IOException();
            }
        } catch (IOException e) {

            System.out.println("输入有误，请重新输入要增加的秒数：");
            this.second = 10;
            Scanner scan = new Scanner(System.in);
            int sec = scan.nextInt();
            this.second = this.second + sec;
        }

        System.out.println("增加后的秒数为：" + this.second);
    }


    public void display() {

        System.out.println("时间信息为：");
        System.out.println(hour + "时");
        System.out.println(minute + "分");
        System.out.println(second + "秒");
    }

    public void addMinute() {

        System.out.println("请输入要增加的分钟数：");
        try {
            Scanner scan = new Scanner(System.in);
            int minute = scan.nextInt();
            this.minute = this.minute + minute;
            if (this.minute > 61) {
                throw new IOException();
            }
        } catch (IOException e) {
            System.out.println("输入有误，请重新输入要增加的分钟数：");
            this.minute = 10;
            Scanner scan = new Scanner(System.in);
            int min = scan.nextInt();
            this.minute = this.minute + min;
        }

        System.out.println("增加后的分钟数为：" + this.minute);
    }


    public void addHour() {

        System.out.println("请输入要增加的小时数：");
        try {
            Scanner scan = new Scanner(System.in);
            int hour = scan.nextInt();
            this.hour = this.hour + hour;
            if (this.hour > 25) {
                throw new IOException();
            }
        } catch (IOException e) {
            System.out.println("输入有误，请重新输入要增加的小时数：");
            this.hour = 10;
            Scanner scan = new Scanner(System.in);
            int hou = scan.nextInt();
            this.hour = this.hour + hou;
        }

        System.out.println("增加后的小时数为：" + this.hour);
    }


    public void subSecond() {
        System.out.println("请输入要减少的秒数：");
        Scanner scan = new Scanner(System.in);
        int sec = scan.nextInt();
        this.second = this.second - sec;
        System.out.println("减少后的秒数为：" + this.second);
    }


    public void subMinute() {
        System.out.println("请输入要减少的分钟数：");
        Scanner scan = new Scanner(System.in);
        int min = scan.nextInt();
        this.minute = this.minute - min;
        System.out.println("减少后的分钟数为：" + this.minute);
    }


    public void subHour() {
        System.out.println("请输入要减少的小时数：");
        Scanner scan = new Scanner(System.in);
        int hou = scan.nextInt();
        this.hour = this.hour - hou;
        System.out.println("减少后的小时数为：" + this.hour);
    }


    public static void main(String[] args) {
        MyTime myTime = new MyTime();
        myTime.display();
        myTime.addSecond();
        myTime.addMinute();
        myTime.addHour();
        myTime.subSecond();
        myTime.subMinute();
        myTime.subHour();
    }
}
